﻿using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.Core.Report.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts.Report;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.NotePrint;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.ServiceHelper;
using System.ComponentModel;
using static System.Net.WebRequestMethods;

namespace NS
{
     /// <summary>

    /// 【单据插件】表格单元格超链接点击事件

    /// </summary>

    [Description("【单据插件】表格单元格超链接点击事件"), HotUpdate]
    public class HyperLink: AbstractSysReportPlugIn
    {
        public override void EntryButtonCellClick(EntryButtonCellClickEventArgs e)
        {
            base.EntryButtonCellClick(e);
            string formid = string.Empty;
            string fldKey = e.FieldKey;
            if(fldKey.EqualsIgnoreCase("FBILLNO"))
            {
                formid = "PUR_PurchaseOrder";
                string FBILLNO = this.SysReportView.Model.DataSource.Rows[e.Row - 1]["FBILLNO"].ToString();
                var requisitionMetadata = (FormMetadata)MetaDataServiceHelper.Load(this.Context, formid);

               // var billNo = this.Model.GetValue(e.FieldKey, e.Row);

                var objs = BusinessDataServiceHelper.Load(this.Context, requisitionMetadata.BusinessInfo

                    , new List<SelectorItemInfo>(new[] { new SelectorItemInfo("FID") })

                    , OQLFilter.CreateHeadEntityFilter("FBillNo='" + FBILLNO + "'"));

                if (objs == null || objs.Length == 0)

                {

                    return;

                }

                var pkId = objs[0]["Id"].ToString();
                BillShowParameter RptParanmeter = new BillShowParameter
                {
                    ParentPageId = this.View.PageId,
                    FormId = formid,
                    PKey = pkId, // 单据内码
                    Status = OperationStatus.VIEW,
                };
                RptParanmeter.PageId = SequentialGuid.NewGuid().ToString();
                RptParanmeter.OpenStyle.ShowType = ShowType.MainNewTabPage;
                RptParanmeter.CustomParams.Add("FBillNo", FBILLNO);
                this.View.ShowForm(RptParanmeter);
            }
            if(string.IsNullOrWhiteSpace(formid))
            {
                return;
            }
        }
    }
}
